﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Simulation
{
	public partial class F_PATH: Form
	{
		C_NODE	ND = new C_NODE();
		
		float[]	ENGY;

		const	int		TT = 16;
		const	int		ET = 100;

		public F_PATH()
		{
			InitializeComponent();

			ENGY = new float[TT];

			Initialize();
			GenerateEvents();
			ImportTextBox();
			ImportGrid();
		}

		public void ImportGrid()
		{
			DG_NDHC[0, 0].Value = ENGY[0].ToString();
			DG_NDHC[1, 0].Value = (ENGY[1] + ENGY[10] + ENGY[13]).ToString();
			DG_NDHC[2, 0].Value = ( ENGY[2] + ENGY[11] + ENGY[14] ).ToString();
			DG_NDHC[3, 0].Value = ( ENGY[3] + ENGY[12] + ENGY[15] ).ToString();

			DG_NDHC[4, 0].Value = ENGY[4].ToString();
			DG_NDHC[5, 0].Value = ENGY[5].ToString();
			DG_NDHC[6, 0].Value = ENGY[6].ToString();

			DG_NDHC[7, 0].Value = ( ENGY[7] + ENGY[8] + ENGY[9] ).ToString();

		}

		public void ImportTextBox()
		{
			TB_ND00.Text = ENGY[ 0].ToString();
			TB_ND01.Text = ENGY[ 1].ToString();
			TB_ND02.Text = ENGY[ 2].ToString();
			TB_ND03.Text = ENGY[ 3].ToString();
			TB_ND04.Text = ENGY[ 4].ToString();

			TB_ND05.Text = ENGY[ 5].ToString();
			TB_ND06.Text = ENGY[ 6].ToString();
			TB_ND07.Text = ENGY[ 7].ToString();
			TB_ND08.Text = ENGY[ 8].ToString();
			TB_ND09.Text = ENGY[ 9].ToString();

			TB_ND10.Text = ENGY[10].ToString();
			TB_ND11.Text = ENGY[11].ToString();
			TB_ND12.Text = ENGY[12].ToString();
			TB_ND13.Text = ENGY[13].ToString();
			TB_ND14.Text = ENGY[14].ToString();
			TB_ND15.Text = ENGY[15].ToString();
		}


		public void GenerateEvents()
		{
			for ( int i = 0; i < ET; i++)
			{
				ENGY[7] = ND.ConsumeEnergyForGeneratingMAC( ENGY[7] );
				ENGY[8] = ND.ConsumeEnergyForGeneratingMAC( ENGY[8] );
				ENGY[9] = ND.ConsumeEnergyForGeneratingMAC( ENGY[9] );

				ENGY[6] = ND.CunsumeReceiving( ENGY[6] );
				ENGY[6] = ND.CunsumeReceiving( ENGY[6] );
				ENGY[6] = ND.CunsumeReceiving( ENGY[6] );
				ENGY[6] = ND.ConsumeTransmitting( ENGY[6] );

				ENGY[5] = ND.CunsumeReceiving( ENGY[5] );

				/* Combined Method *********************************/
				//for ( int p = 5; p >= 2; p -- )
				//{
				//    ENGY[p] = ND.CunsumeReceiving( ENGY[p] );
				//    ENGY[p] = ND.ConsumeTransmitting( ENGY[p] );
				//}
				/**************************************************/

				/* Proposed Method *********************************/
				if ( i % 50 == 0 )
				{
					ENGY[2] = ND.ConsumeTransmitting( ENGY[2] );
					ENGY[1] = ND.CunsumeReceiving( ENGY[1] );

					ENGY[2] = ND.ConsumeTransmitting( ENGY[2] );
					ENGY[3] = ND.CunsumeReceiving( ENGY[3] );
					
					for ( int s = 10; s <= 15; s++ )
					{
						ENGY[2] = ND.ConsumeTransmitting( ENGY[2] );
						ENGY[s] = ND.CunsumeReceiving( ENGY[s] );
					}
				}
				/**************************************************/
			}
		}

		public void Initialize()
		{
			

			//for ( int i = 0; i < TT; i++ )
			//{
			//    if ( ( i == 2 ) || ( i == 6 ) )
			//        SN[i].CMND = true;
			//}
		}
	}
}
